package com.icss.mqsp.data.process.impl;

import com.icss.mqsp.data.process.IDataProcessor;
import com.icss.mqsp.model.ReportDefine;
import com.icss.pangu.logging.Log;
import com.icss.pangu.logging.LogFactory;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class TableDataProcessor
  implements IDataProcessor
{
  private static Log log = LogFactory.getLog(TableDataProcessor.class);
  
  public JSONObject processData(ReportDefine rd, String data, Map<String, String> condition)
  {
    log.info("TableDataProcessor 开始执行 ********************");
    log.info(data);
    JSONObject js = new JSONObject();
    js.put("appid", rd.getAppid());
    StringBuffer sb = new StringBuffer();
    sb.append("[");
    JSONArray dataJs = JSONArray.fromObject(data);
    for (int i = 0; i < dataJs.size(); i++)
    {
      JSONObject js1 = dataJs.getJSONObject(i);
      int len = js1.size();
      sb.append("[");
      for (int j = 1; j <= len; j++) {
        sb.append("\"" + js1.getString(new StringBuilder("col").append(j).toString()) + "\",");
      }
      sb.append("],");
    }
    sb.append("]");
    String sbdata = sb.toString().replaceAll(",]", "]");
    js.put("data", sbdata);
    log.info(sbdata);
    log.info("TableDataProcessor 结束执行 ********************");
    return js;
  }
}
